package com.mysen.sso.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.mysen.model.Response;
import com.mysen.sso.dao.RoleDao;
import com.mysen.sso.model.Role;
import com.mysen.sso.service.RoleService;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleDao dao;
	
	@Override
	public Response<?> selectByPage(Role record) {
		Response<?> resp = new Response<>();
		resp.setTotal(dao.selectByPageCount(record));
		if(resp.getTotal() > 0) {
			resp.setDatas(dao.selectByPage(record));
		}
		resp.setSuccess(true);
		return resp;
	}
	
	@Override
	public Role save(Role record) {
		dao.insert(record);
		return record;
	}

	@Override
	public void updateById(Role record) {
		dao.updateById(record);
	}

	@Override
	public void deleteById(String id) {
		dao.deleteById(id);
	}

	@Override
	public Role selectById(String id) {
		return dao.selectById(id);
	}

	@Override
	public void addPermissions(Role record) {
		dao.addPermissions(record);
	}

	@Override
	public List<Role> selectTree(String pid, boolean isAll) {
		if(isAll) {
			return dao.selectTree(pid);
		}else {
			Role role = new Role();
			role.setRolePid(pid);
			return dao.selectByPage(role);
		}
	}

}
